import Vue from 'vue'
import VueRouter from 'vue-router'
import Home from '../views/Home.vue'

Vue.use(VueRouter)

const routes = [
  {
    path: '/Home',
    name: 'Home',
    component: Home,
    children: [
      {
        path: '/shouye',
        name: 'shouye',
        component: () => import('../views/shouye/index.vue'),
        children: [
          {
            path: '/Guanmanagement',
            name: 'Guanmanagement',
            component: () => import('../views/shouye/Guanmanagement.vue')
          },
          {
            path: '/Imgmanagement',
            name: 'Imgmanagement',
            component: () => import('../views/shouye/Imgmanagement.vue')
          },
          {
            path: '/Shopmanagement',
            name: 'Shopmanagement',
            component: () => import('../views/shouye/Shopmanagement.vue')
          },
        ]
      },
    ]
  },
  {
    path: '/about',
    name: 'About',
    component: () => import('../views/About.vue')
  },
  {
    path: '/login',
    name: 'login',
    component: () => import('../views/login.vue')
  }
]




const router = new VueRouter({
  routes
})
router.beforeEach((to, from, next) => {
  if (localStorage.getItem("token")) {
    next()
  } else {
    if (to.path == "/login") {
      next()
    } else {
      next("/login")
    }
  }
})

export default router
